// 封装各种请求
// 导入已创建的axios实例
import request from "@/utils/request";
const http = {
    /**
     * get请求
     * @param {String} url 请求地址
     * @param {Object} params 请求参数get,delete;放在url中;
     * data用于post,put;放在请求体中
     */
    get(url: string, params: Object) {
        const config: {
            method: string,
            url: string,
            params?: Object
        } = {
            method: "get",
            url: url,
        };
        // 如果有参数,设置到config中
        if (params) {
            config.params = params;
        }
        return request(config);
    },
    // post请求
    post(url: string, params: Object) {
        const config: {
            method: string,
            url: string,
            data?: Object
        } = {
            method: "post",
            url: url,
        };
        // 如果有参数,设置到config中，设置data
        if (params) {
            config.data = params;
        }
        return request(config);
    },
    // delete请求
    delete(url: string, params: Object) {
        const config: {
            method: string,
            url: string,
            params?: Object
        } = {
            method: "delete",
            url: url,
        };
        // 如果有参数,设置到config中
        if (params) {
            config.params = params;
        }
        return request(config);
    },
    // put请求
    put(url: string, params: Object) {
        const config: {
            method: string,
            url: string,
            data?: Object
        } = {
            method: "put",
            url: url,
        };
        // 如果有参数,设置到config中，设置data
        if (params) {
            config.data = params;
        }
        return request(config);
    }
};
// 导出
export default http;